﻿using System.Web.Mvc;
using Authentication.Configuration;
using Common.Contract;
using Common.Contract.SaleOut;
using Common.Contract.SaleOut.Request;
using Common.Contract.SaleOut.Record;
using Common.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using Common.Service.DataTables;
using Common.Contract.Paging;
using Common.Type;
using Authentication.Model.ViewModel.SaleOut;

namespace Authentication.Web.Controller
{
    public class SaleOutController : ControllerBase
    {
        #region Saleout Daily
        [Authorize]
        public ActionResult SellOutDaily(string FromDate, string ToDate, string ShopCode, string ProdL1, string Model, string ModelSuffix, string IncentiveFlag, string SMSYN, string Region, string SerialNo)
        {
            return View();
        }
        [HttpPost]
        public ActionResult SellOutDaily(SellOutDailyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("SellOutDaily", "saleout", new { FromDate = vm.FromDate.ToString("MM/dd/yyyy"), ToDate = vm.ToDate.ToString("MM/dd/yyyy") });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }

            return View();
        }

        [HttpPost]
        public ActionResult SellOutDailyData(DataTablesPageRequest pageRequest, string fromDate, string toDate)
        {
            DateTime date = DateTime.Now;
            var firsDayOfMonth = new DateTime(date.Year, date.Month, 1);
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveSellOutDailyRequest request = new RetrieveSellOutDailyRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.Index"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    FromDate = string.IsNullOrEmpty(fromDate) ? firsDayOfMonth.ToString("MM/dd/yyyy") : fromDate,
                    ToDate = string.IsNullOrEmpty(toDate) ? firsDayOfMonth.AddMonths(1).AddDays(-1).ToString("MM/dd/yyyy") : toDate
                };
                var sellOutDailyRecords = serviceClient.Proxy.RetrieveSellOutDaily(request);
                var resultDailyReport = (sellOutDailyRecords == null || sellOutDailyRecords.Records == null) ? new List<SellOutDailyRecord>() : sellOutDailyRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = sellOutDailyRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultDailyReport.Select(x => new object[]{
                                                             x.Region, 
                                                             x.CustName,
                                                             x.CustType,
                                                             x.Province,
                                                             x.BelongToBill,
                                                             x.Channel,
                                                             x.ShopCell,
                                                             x.UserCell,
                                                             x.BillCode,
                                                             x.BillName,
                                                             x.Division,
                                                             x.ProdL1,
                                                             x.ProdL2,
                                                             x.ProdL3,
                                                             x.ProdL4,
                                                             x.Grade,
                                                             x.Model,
                                                             x.ModelSuffix,
                                                             x.MRP,
                                                             x.SerialNo,
                                                             x.SellInDate,
                                                             x.SellOutDate,
                                                             x.Amount,
                                                             x.CFM_Date,
                                                             x.SellOutDate
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }
        #endregion

        #region Saleout Weekly
        [Authorize]
        public ActionResult SellOutWeekly(string Region, string FromDate, string ToDate, string Product, string ShopName, string Model)
        {
            return View();
        }

        [HttpPost]
        public ActionResult SellOutWeekly(SellOutWeeklyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("SellOutWeekly", "saleout", new { FromDate = vm.FromDate.ToString("MM/dd/yyyy"), ToDate = vm.ToDate.ToString("MM/dd/yyyy") });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }

            return View();
        }

        [HttpPost]
        public ActionResult SellOutWeeklyData(DataTablesPageRequest pageRequest, string fromDate, string toDate)
        {
            DateTime date = DateTime.Now;
            var firsDayOfMonth = new DateTime(date.Year, date.Month, 1);
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveSellOutWeeklyRequest request = new RetrieveSellOutWeeklyRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.Index"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    FromDate = string.IsNullOrEmpty(fromDate) ? firsDayOfMonth.ToString("MM/dd/yyyy") : fromDate,
                    ToDate = string.IsNullOrEmpty(toDate) ? firsDayOfMonth.AddMonths(1).AddDays(-1).ToString("MM/dd/yyyy") : toDate
                };
                var sellOutWeeklyRecords = serviceClient.Proxy.RetrieveSellOutWeekly(request);
                var resultDailyReport = (sellOutWeeklyRecords == null || sellOutWeeklyRecords.Records == null) ? new List<SellOutWeeklyRecord>() : sellOutWeeklyRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = sellOutWeeklyRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultDailyReport.Select(x => new object[]{
                                                             x.Region, 
                                                             x.ShopName,
                                                             x.Product,
                                                             x.Model,
                                                             x.NonIncentiveQty,
                                                             x.IncentiveQty,
                                                             x.Qty,
                                                             x.AMT
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }
        #endregion

        #region Daily report
        [Authorize]
        [HttpGet]
        public ActionResult ReportDaily(string fromDate, string toDate)
        {
            return View();
        }

        [HttpPost]
        public ActionResult ReportDaily(SaleOutDailyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("ReportDaily", "saleout", new { FromDate = vm.FromDate.ToString("MM/dd/yyyy"), ToDate = vm.ToDate.ToString("MM/dd/yyyy") });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }

            return View();
        }

        [HttpPost]
        public ActionResult ReportDailyData(DataTablesPageRequest pageRequest, string fromDate, string toDate)
        {
            DateTime date = DateTime.Now;
            var firsDayOfMonth = new DateTime(date.Year, date.Month, 1);
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveDailyReportRequest request = new RetrieveDailyReportRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.Index"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    FromDate = string.IsNullOrEmpty(fromDate) ? firsDayOfMonth.ToString("MM/dd/yyyy") : fromDate,
                    ToDate = string.IsNullOrEmpty(toDate) ? firsDayOfMonth.AddMonths(1).AddDays(-1).ToString("MM/dd/yyyy") : toDate
                };
                var dailyReportRecords = serviceClient.Proxy.RetrieveDailyReport(request);
                var resultDailyReport = (dailyReportRecords == null || dailyReportRecords.Records == null) ? new List<DailyReportRecord>() : dailyReportRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = dailyReportRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultDailyReport.Select(x => new object[]{
                                                             x.ShopCode,
                                                             x.ShopName,
                                                             x.Product,
                                                             x.Model,
                                                             x.Region, 
                                                             x.Province,
                                                             x.Sum,
                                                             x.Mon,
                                                             x.Tue,
                                                             x.Wed,
                                                             x.Thu, 
                                                             x.Fri,
                                                             x.Sat,
                                                             x.Sun
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }
        #endregion

        #region Weekly report
        [Authorize]
        [HttpGet]
        public ActionResult ReportWeekly(string YearMonth)
        {
            return View();
        }

        [HttpPost]
        public ActionResult ReportWeekly(SaleOutWeeklyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("ReportWeekly", "saleout", new { YearMonth = (new DateTime(vm.YearMonth.Year, vm.YearMonth.Month, 1)).ToString("MM/dd/yyyy") });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }

            return View();
        }
        [HttpPost]
        public ActionResult ReportWeeklyData(DataTablesPageRequest pageRequest, string yearMonth)
        {
            var date = DateTime.Now;
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveWeeklyReportRequest request = new RetrieveWeeklyReportRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.MonthlyReport"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    YearMonth = string.IsNullOrEmpty(yearMonth) ? (new DateTime(date.Year, date.Month, 1)).ToString("MM/dd/yyyy") : yearMonth.ToString()
                };
                var weeklyReportRecords = serviceClient.Proxy.RetrieveWeeklyReport(request);
                var resultDailyReport = (weeklyReportRecords == null || weeklyReportRecords.Records == null) ? new List<WeeklyReportRecord>() : weeklyReportRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = weeklyReportRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultDailyReport.Select(x => new object[]{x.Region, 
                                                             x.Province,
                                                             x.ShopCode,
                                                             x.ShopName,
                                                             x.Product,
                                                             x.Model,
                                                             x.ACM,
                                                             x.W1,
                                                             x.W2,
                                                             x.W3,
                                                             x.W4, 
                                                             x.W5
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }

        #endregion

        #region Monthly report
        [Authorize]
        [HttpGet]
        public ActionResult ReportMonthly(string Year)
        {
            return View();
        }
        [HttpPost]
        public ActionResult ReportMonthly(SaleOutMonthlyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("ReportMonthly", "saleout", new { FromDate = vm.Year.Year.ToString("MM/dd/yyyy") });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }

            return View();
        }

        [HttpPost]
        public ActionResult ReportMonthlyData(DataTablesPageRequest pageRequest, string Year)
        {
            var date = DateTime.Now;
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveMonthlyReportRequest request = new RetrieveMonthlyReportRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.MonthlyReport"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    Year = string.IsNullOrWhiteSpace(Year) ? date.Year.ToString() : Year
                };
                var monthlyReportRecords = serviceClient.Proxy.RetrieveMonthlyReport(request);
                var resultDailyReport = (monthlyReportRecords == null || monthlyReportRecords.Records == null) ? new List<MonthlyReportRecord>() : monthlyReportRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = monthlyReportRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultDailyReport.Select(x => new object[]{x.Region, 
                                                             x.Province,
                                                             x.ShopCode,
                                                             x.ShopName,
                                                             x.Product,
                                                             x.Model,
                                                             x.ACM,
                                                             x.Jan,
                                                             x.Feb,
                                                             x.Mar,
                                                             x.Apr, 
                                                             x.May,
                                                             x.Jun,
                                                             x.Jul,
                                                             x.Aug,
                                                             x.Sep,
                                                             x.Oct,
                                                             x.Nov,
                                                             x.Dec
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }
        #endregion

        #region Inventory Daily Report
        [Authorize]
        [HttpGet]
        public ActionResult ReportInventoryDaily(string FromDate, string ToDate)
        {
            return View();
        }

        [HttpPost]
        public ActionResult ReportInventoryDaily(InventoryDailyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("reportinventorydaily", "saleout", new { FromDate = vm.FromDate.ToString("MM/dd/yyyy"), ToDate = vm.ToDate.ToString("MM/dd/yyyy") });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }
            return View(vm);
        }

        [HttpPost]
        public ActionResult ReportInventoryDailyData(DataTablesPageRequest pageRequest, string fromDate, string toDate)
        {
            DateTime date = DateTime.Now;
            var firsDayOfMonth = new DateTime(date.Year, date.Month, 1);
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveInventoryDailyReportRequest request = new RetrieveInventoryDailyReportRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.ReportInventoryDailyData"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    FromDate = string.IsNullOrEmpty(fromDate) ? firsDayOfMonth.ToString("MM/dd/yyyy") : fromDate,
                    ToDate = string.IsNullOrEmpty(toDate) ? firsDayOfMonth.AddMonths(1).AddDays(-1).ToString("MM/dd/yyyy") : toDate
                };
                var reportRecords = serviceClient.Proxy.RetrieveInventoryDailyReport(request);
                var resultReport = (reportRecords == null || reportRecords.Records == null) ? new List<InventoryDailyReportRecord>() : reportRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = reportRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultReport.Select(x => new object[]{x.Region, 
                                                             x.BillToCode,
                                                             x.BillToName,
                                                             x.Product,
                                                             x.Model,
                                                             x.OrderQty,
                                                             x.Inventory,
                                                             x.Sum,
                                                             x.Mon,
                                                             x.Tue,
                                                             x.Wed,
                                                             x.Thu, 
                                                             x.Fri,
                                                             x.Sat,
                                                             x.Sun
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }
        #endregion

        #region Inventory Weekly report

        public ActionResult ReportInventoryWeekly(string YearMonth)
        {
            return View();
        }

        [HttpPost]
        public ActionResult ReportInventoryWeekly(InventoryWeeklyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("reportinventoryweekly", "saleout", new { FromDate = vm.YearMonth });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }

            return View(vm);
        }
        [HttpPost]
        public ActionResult ReportInventoryWeeklyData(DataTablesPageRequest pageRequest, string fromDate, string toDate)
        {
            DateTime date = DateTime.Now;
            var firsDayOfMonth = new DateTime(date.Year, date.Month, 1);
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveInventoryWeeklyReportRequest request = new RetrieveInventoryWeeklyReportRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.ReportInventoryDailyData"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    FromDate = string.IsNullOrEmpty(fromDate) ? firsDayOfMonth.ToString("MM/dd/yyyy") : fromDate,
                    ToDate = string.IsNullOrEmpty(toDate) ? firsDayOfMonth.AddMonths(1).AddDays(-1).ToString("MM/dd/yyyy") : toDate
                };
                var reportRecords = serviceClient.Proxy.RetrieveInventoryWeeklyReport(request);
                var resultReport = (reportRecords == null || reportRecords.Records == null) ? new List<InventoryWeeklyReportRecord>() : reportRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = reportRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultReport.Select(x => new object[]{x.Region, 
                                                             x.BillToCode,
                                                             x.BillToName,
                                                             x.Product,
                                                             x.Model,
                                                             x.Stock,
                                                             x.Inventory,
                                                             x.ACM,
                                                             x.W1,
                                                             x.W2,
                                                             x.W3,
                                                             x.W4, 
                                                             x.W5
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }
        #endregion
        #region Inventory Monthly report
        public ActionResult ReportInventoryMonthly(string Region, string Year, string Product, string BillToCode, string Model)
        {
            return View();
        }
        [HttpPost]
        public ActionResult ReportInventoryMonthly(SaleOutMonthlyViewModel vm, FormCollection form)
        {
            try
            {
                if (form["btnSearch"] != null)
                {
                    return RedirectToAction("ReportMonthly", "saleout", new { FromDate = vm.Year.Year.ToString("MM/dd/yyyy") });
                }
            }
            catch (Exception ex)
            {
                vm.MessageType = MessageType.Error;
                vm.Message = ex.ToString();
            }

            return View();
        }

        [HttpPost]
        public ActionResult ReportInventoryMonthlyData(DataTablesPageRequest pageRequest, string Year)
        {
            var date = DateTime.Now;
            DataTableResponse pageResponse = null;
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveInventoryMonthlyReportRequest request = new RetrieveInventoryMonthlyReportRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.SaleOutController.MonthlyReport"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    TextSearch = pageRequest.Search.Trim(),
                    Year = string.IsNullOrWhiteSpace(Year) ? date.Year.ToString() : Year
                };
                var monthlyReportRecords = serviceClient.Proxy.RetrieveInventoryMonthlyReport(request);
                var resultDailyReport = (monthlyReportRecords == null || monthlyReportRecords.Records == null) ? new List<InventoryMonthlyReportRecord>() : monthlyReportRecords.Records;
                pageResponse = new DataTableResponse
                {
                    sEcho = pageRequest.Echo,
                    iTotalRecords = monthlyReportRecords.Page.TotalRecords,
                    sColumns = pageRequest.ColumnNames,
                    aaData = resultDailyReport.Select(x => new object[]{x.Region, 
                                                             x.BillToCode,
                                                             x.BillToName,
                                                             x.Product,
                                                             x.Model,
                                                             x.Stock,
                                                             x.Inventory,
                                                             x.ACM,
                                                             x.Jan,
                                                             x.Feb,
                                                             x.Mar,
                                                             x.Apr, 
                                                             x.May,
                                                             x.Jun,
                                                             x.Jul,
                                                             x.Aug,
                                                             x.Sep,
                                                             x.Oct,
                                                             x.Nov,
                                                             x.Dec
                    }).ToList()
                };
            }
            return Json(pageResponse);
        }
        #endregion
        #region N/A
        [Authorize]
        public ActionResult SellOutSMSHit(string FromDate, string ToDate, string SMSType, string ShopCell, string RegionID, string RSPType, string MSGBody)
        {
            var vm = new SellOutSMSHisViewModel();
            using (ServiceClient<ISaleOut> serviceClient = new ServiceClient<ISaleOut>())
            {
                RetrieveSellOutSMSHisRequest request = new RetrieveSellOutSMSHisRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "Authentication.Web.Controller.HomeController.Index"
                    },
                    FromDate = FromDate,
                    ToDate = ToDate,
                    SMSType = SMSType,
                    ShopCell = ShopCell,
                    RegionID = RegionID,
                    RSPType = RSPType,
                    MSGBody = MSGBody
                };

                var response = serviceClient.Proxy.RetrieveSellOutSMSHis(request);
                vm.ListRecord = response.Records;
                var yy = response.Page.TotalRecords;
            }
            return View(vm);
        }


        #endregion
    }
}
